//
//  LeYouView.m
//  LeYou_demo
//
//  Created by naffan on 12-11-18.
//  Copyright (c) 2012年 naffan. All rights reserved.
//

#import "LeYouView.h"

@implementation LeYouView

//@synthesize delegate;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //codes here
    }
    return self;
}
//为了注册返回时写的
-(void)loadloginview{
    //解决显示网页后回跳时页面仍有显示的问题
    UIWebView* WebView  = [[ UIWebView   alloc]  initWithFrame: CGRectMake(0, 0,768, 1024)];
    [WebView loadHTMLString:@" " baseURL:nil];
    [self addSubview:WebView];
    //
    [self setFrame:CGRectMake(0, 0, 768, 1024)];
    self.backgroundColor = [UIColor whiteColor];
    //标题
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(95, 10, 140, 30)];
    titleLabel.text = @"乐游SDK登入";
    titleLabel.font = [UIFont systemFontOfSize:18];
    //用户名标题
    label1 = [[UILabel alloc] initWithFrame:CGRectMake(15, 60.0f, 70, 30)];
    label1.backgroundColor = [UIColor clearColor];
    label1.font = [UIFont fontWithName:@"Helvetica-Bold"size:18];
    label1.text = @"用户名";
    label1.textColor = [UIColor blackColor];
    //密码标题
    label2 = [[UILabel alloc] initWithFrame:CGRectMake(15, 100.0f, 70, 30)];
    label2.backgroundColor = [UIColor clearColor];
    label2.font = [UIFont fontWithName:@"Helvetica-Bold"size:18];
    label2.text = @"密码";
    label2.textColor = [UIColor blackColor];
    //加入视图
    [self addSubview:titleLabel];
    [self addSubview:label1];
    [self addSubview:label2];
    /**********************************************************************************/
    //用户名文本框
    accountField = [[UITextField alloc] initWithFrame:CGRectMake(95.0f, 60.0f, 190.0f, 30.0f)];
    [accountField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型
    accountField.placeholder = @"用户名"; //默认显示的字
    accountField.secureTextEntry = NO; //是否以密码形式显示
    accountField.tag = 0;
    //密码文本框
    passwdField = [[UITextField alloc]initWithFrame:CGRectMake(95.0f, 100.0f, 190.0f, 30.0f)];
    [passwdField setBorderStyle:UITextBorderStyleRoundedRect];
    passwdField.placeholder = @"密码"; //默认显示的字
    passwdField.secureTextEntry = YES; //是否以密码形式显示
    accountField.tag = 1;
    //加入试图
    [self addSubview:passwdField];
    [self addSubview:accountField];
    /**********************************************************************************/
    //登入按钮
    btn_login = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn_login setFrame:CGRectMake(50, 150.0f, 70, 30)];
    [btn_login setTitle:@"登入" forState:UIControlStateNormal];
    [btn_login addTarget:self action:@selector(buttonReleaseForLogin:) forControlEvents:UIControlEventTouchDown];
    //[btn_login addTarget:self action:@selector(buttonReleaseForLogin:) forControlEvents:UIControlEventTouchUpInside];
    //注册按钮
    btn_register = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn_register setFrame:CGRectMake(130, 150.0f, 70, 30)];
    [btn_register setTitle:@"注册" forState:UIControlStateNormal];
    [btn_register addTarget:self action:@selector(buttonReleaseForRegister:) forControlEvents:UIControlEventTouchDown];
    //找回密码按钮
    btn_findpassword = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn_findpassword setFrame:CGRectMake(210, 150.0f, 70, 30)];
    [btn_findpassword setTitle:@"找回密码" forState:UIControlStateNormal];
    [btn_findpassword addTarget:self action:@selector(buttonReleaseForFindPassword:) forControlEvents:UIControlEventTouchDown];
    //加入视图
    [self addSubview:btn_login];
    [self addSubview:btn_register];
    [self addSubview:btn_findpassword];
}

//登入界面
- (id)init
{
    if ((self = [super init]))
    {
        //二次验证
        lylogin = [[LYLogin alloc]init];
        Boolean logined = [lylogin isLogined];
        if(logined == YES){
            [self showLoginPage];
        }else{
            [self setFrame:CGRectMake(0, 0, 768, 1024)];
            self.backgroundColor = [UIColor whiteColor];
            //标题
            titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(95, 10, 140, 30)];
            titleLabel.text = @"乐游SDK登入";
            titleLabel.font = [UIFont systemFontOfSize:18];
            //用户名标题
            label1 = [[UILabel alloc] initWithFrame:CGRectMake(15, 60.0f, 70, 30)];
            label1.backgroundColor = [UIColor clearColor];
            label1.font = [UIFont fontWithName:@"Helvetica-Bold"size:18];
            label1.text = @"用户名";
            label1.textColor = [UIColor blackColor];
            //密码标题
            label2 = [[UILabel alloc] initWithFrame:CGRectMake(15, 100.0f, 70, 30)];
            label2.backgroundColor = [UIColor clearColor];
            label2.font = [UIFont fontWithName:@"Helvetica-Bold"size:18];
            label2.text = @"密码";
            label2.textColor = [UIColor blackColor];
            //加入视图
            [self addSubview:titleLabel];
            [self addSubview:label1];
            [self addSubview:label2];
            /**********************************************************************************/
            //用户名文本框
            accountField = [[UITextField alloc] initWithFrame:CGRectMake(95.0f, 60.0f, 190.0f, 30.0f)];
            [accountField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型
            accountField.placeholder = @"用户名"; //默认显示的字
            accountField.secureTextEntry = NO; //是否以密码形式显示
            accountField.tag = 0;
            //密码文本框
            passwdField = [[UITextField alloc]initWithFrame:CGRectMake(95.0f, 100.0f, 190.0f, 30.0f)];
            [passwdField setBorderStyle:UITextBorderStyleRoundedRect];
            passwdField.placeholder = @"密码"; //默认显示的字
            passwdField.secureTextEntry = YES; //是否以密码形式显示
            accountField.tag = 1;
            //加入试图
            [self addSubview:passwdField];
            [self addSubview:accountField];
            /**********************************************************************************/
            //登入按钮
            btn_login = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [btn_login setFrame:CGRectMake(50, 150.0f, 70, 30)];
            [btn_login setTitle:@"登入" forState:UIControlStateNormal];
            [btn_login addTarget:self action:@selector(buttonReleaseForLogin:) forControlEvents:UIControlEventTouchDown];
            //[btn_login addTarget:self action:@selector(buttonReleaseForLogin:) forControlEvents:UIControlEventTouchUpInside];
            //注册按钮
            btn_register = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [btn_register setFrame:CGRectMake(130, 150.0f, 70, 30)];
            [btn_register setTitle:@"注册" forState:UIControlStateNormal];
            [btn_register addTarget:self action:@selector(buttonReleaseForRegister:) forControlEvents:UIControlEventTouchDown];
            //找回密码按钮
            btn_findpassword = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [btn_findpassword setFrame:CGRectMake(210, 150.0f, 70, 30)];
            [btn_findpassword setTitle:@"找回密码" forState:UIControlStateNormal];
            [btn_findpassword addTarget:self action:@selector(buttonReleaseForFindPassword:) forControlEvents:UIControlEventTouchDown];
            //加入视图
            [self addSubview:btn_login];
            [self addSubview:btn_register];
            [self addSubview:btn_findpassword];
        }
        
    }
    return self;
}
						
//注册界面
- (void)showRegisterPage
{
    [self setFrame:CGRectMake(0, 0, 768, 1024)];
    self.backgroundColor = [UIColor whiteColor];
    //标题
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(95, 10, 140, 30)];
    titleLabel.text = @"注册";
    titleLabel.font = [UIFont systemFontOfSize:18];
    //用户名标题
    label1 = [[UILabel alloc] initWithFrame:CGRectMake(15, 60.0f, 70, 30)];
    label1.backgroundColor = [UIColor clearColor];
    label1.font = [UIFont fontWithName:@"Helvetica-Bold"size:18];
    label1.text = @"用户名";
    label1.textColor = [UIColor blackColor];
    //密码标题
    label2 = [[UILabel alloc] initWithFrame:CGRectMake(15, 100.0f, 70, 30)];
    label2.backgroundColor = [UIColor clearColor];
    label2.font = [UIFont fontWithName:@"Helvetica-Bold"size:18];
    label2.text = @"密码";
    label2.textColor = [UIColor blackColor];
    //确认密码标题
    label3 = [[UILabel alloc] initWithFrame:CGRectMake(15, 140.0f, 120, 30)];
    label3.backgroundColor = [UIColor clearColor];
    label3.font = [UIFont fontWithName:@"Helvetica-Bold"size:18];
    label3.text = @"确认密码";
    label3.textColor = [UIColor blackColor];
    //加入视图
    [self addSubview:label1];
    [self addSubview:label2];
    [self addSubview:label3];
    [self addSubview:titleLabel];
    
    /**********************************************************************************/
    //用户名文本框
    accountField = [[UITextField alloc] initWithFrame:CGRectMake(95.0f, 60.0f, 190.0f, 30.0f)];
    [accountField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型
    NSString* name=[lylogin getRegisterName];
    if(name != nil){
        accountField.text = name; //默认显示的字
    }else{
         accountField.placeholder = @"用户名"; //默认显示的字
    }
    accountField.secureTextEntry = NO; //是否以密码形式显示
    accountField.tag = 0;
    //密码文本框 1
    passwdField = [[UITextField alloc]initWithFrame:CGRectMake(95.0f, 100.0f, 190.0f, 30.0f)];
    [passwdField setBorderStyle:UITextBorderStyleRoundedRect];
    passwdField.placeholder = @"密码"; //默认显示的字
    passwdField.secureTextEntry = YES; //是否以密码形式显示
    accountField.tag = 1;
    //密码文本框 2
    passwdField_again = [[UITextField alloc]initWithFrame:CGRectMake(95.0f, 140.0f, 190.0f, 30.0f)];
    [passwdField_again setBorderStyle:UITextBorderStyleRoundedRect];
    passwdField_again.placeholder = @"确认密码"; //默认显示的字
    passwdField_again.secureTextEntry = YES; //是否以密码形式显示
    passwdField_again.tag = 2;
    //加入试图
    [self addSubview:accountField];
    [self addSubview:passwdField];
    [self addSubview:passwdField_again];
    
    /**********************************************************************************/
    //注册按钮
    btn_register = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn_register setFrame:CGRectMake(90, 180.0f, 70, 30)];
    [btn_register setTitle:@"提交" forState:UIControlStateNormal];
    [btn_register addTarget:self action:@selector(buttonReleaseForRegisterSubmit:) forControlEvents:UIControlEventTouchDown];
    //注册取消
    btn_cancel = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn_cancel setFrame:CGRectMake(180, 180.0f, 70, 30)];
    [btn_cancel setTitle:@"返回" forState:UIControlStateNormal];
    [btn_cancel addTarget:self action:@selector(buttonReleaseForCancel:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:btn_register];
    [self addSubview:btn_cancel];
}

//登入后页面
- (void)showLoginPage
{
    //标题
    [self setFrame:CGRectMake(0, 0, 768, 1024)];
    self.backgroundColor = [UIColor whiteColor];
    UILabel *titleLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(95, 10, 140, 30)];
    titleLabel3.text = @"登陆后的页面";
    titleLabel3.font = [UIFont systemFontOfSize:18];
    [self addSubview:titleLabel3];
    
    btn_logout = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn_logout setFrame:CGRectMake(50, 190.0f, 70, 30)];
    [btn_logout setTitle:@"退出" forState:UIControlStateNormal];
    [btn_logout addTarget:self action:@selector(buttonReleaseForLogout:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:btn_logout];
    
    btn_fill = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn_fill setFrame:CGRectMake(125, 190.0f, 70, 30)];
    [btn_fill setTitle:@"充值" forState:UIControlStateNormal];
    [btn_fill addTarget:self action:@selector(buttonReleaseForFill:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:btn_fill];
    
    
    btn_fillrecord = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn_fillrecord setFrame:CGRectMake(200, 190.0f, 70, 30)];
    [btn_fillrecord setTitle:@"查询记录" forState:UIControlStateNormal];
    [btn_fillrecord addTarget:self action:@selector(buttonReleaseForFillRecord:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:btn_fillrecord];
}



//登入按钮操作
-(void)buttonReleaseForLogin:(id)sender
{
    if([accountField text] == nil || [accountField text].length == 0){
        alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                    message:@"请输入用户名"
                                    delegate:self
                                    cancelButtonTitle:@"取消"
                                    otherButtonTitles:nil
                 ];
        [alert show];
        [alert release];
        return;
    }
    if([passwdField text] == nil || [passwdField text].length == 0){
        alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                          message:@"请输入密码"
                                         delegate:self
                                cancelButtonTitle:@"取消"
                                otherButtonTitles:nil
                 ];
        [alert show];
        [alert release];
        return;
    }
    NSMutableDictionary *data = [NSMutableDictionary dictionary];
    [data setValue:[accountField text] forKey:@"name"];
    [data setValue:[passwdField text] forKey:@"password"];
    lylogin = [[LYLogin alloc]init] ;
    Boolean loginresult = [lylogin logIn:[data objectForKey:@"name"] password:[data objectForKey:@"password"]];
    if (loginresult == YES) {
        [label1 removeFromSuperview];
        [label2 removeFromSuperview];
        [accountField removeFromSuperview];
        [passwdField removeFromSuperview];
        [btn_login removeFromSuperview];
        [btn_register removeFromSuperview];
        [btn_findpassword removeFromSuperview];
        [self showLoginPage];
    }else{
        alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                          message:@"用户名与密码不匹配"
                                         delegate:self
                                cancelButtonTitle:@"取消"
                                otherButtonTitles:nil
                 ];
        [alert show];
        [alert release];
        return;
    }
    [lylogin release];
}

//注册按钮操作
-(void)buttonReleaseForRegister:(id)sender
{
    [label1 removeFromSuperview];
    [label2 removeFromSuperview];
    [accountField removeFromSuperview];
    [passwdField removeFromSuperview];
    [btn_login removeFromSuperview];
    [btn_register removeFromSuperview];
    [btn_findpassword removeFromSuperview];
    
    [self showRegisterPage];
}

//找回密码操作
-(void)buttonReleaseForFindPassword:(id)sender;
{
    [self loadFindPasswordPage];
}

//找回密码页面
-(void)loadFindPasswordPage{
    LeYou *leyou = [[LeYou alloc]init];
    UIWebView* WebView  = [[ UIWebView   alloc]  initWithFrame: CGRectMake(0, 0,320, 1024)];
    NSString *url_base = LeYouApiUrlBase;
    NSString* url_api_for_findpaypass = [url_base stringByAppendingString:@"orderList.shtml"];
    NSURL *url = [NSURL URLWithString:url_api_for_findpaypass];
    NSString *mac = [leyou md5:[appid stringByAppendingFormat:@"%@",PRIVATE_KEY]];
    /*
     NSLog(@"appid : %@",appid);
     NSLog(@"uid : %@",uid);
     NSLog(@"mac : %@",[appid stringByAppendingFormat:@"%@%@",uid,PRIVATE_KEY]);
     */
    //POST打开页面 关键次：UIWebview post值
    NSString *body = [NSString stringWithFormat: @"appid=%@&mac=%@",appid,mac];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
    [request setHTTPMethod: @"POST"];
    [request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
    [WebView loadRequest: request];
    [self addSubview:WebView];
    
    
    /*
    UIWebView* WebView  = [[ UIWebView   alloc]  initWithFrame: CGRectMake(0, 0,320, 1024)];
    NSString *url_base = LeYouApiUrlBase;
    NSString* url_api_for_findpaypass = [url_base stringByAppendingString:@"getpassword.shtml"];
    NSURL *url = [NSURL URLWithString:url_api_for_findpaypass];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
    [WebView loadRequest: request];
    [self addSubview:WebView];
     */
    //返回
    btn_cancel = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn_cancel setFrame:CGRectMake(180, 180.0f, 70, 30)];
    [btn_cancel setTitle:@"返回" forState:UIControlStateNormal];
    [btn_cancel addTarget:self action:@selector(buttonReleaseForCancel:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:btn_cancel];

    
}
//登出按钮操作
-(void)buttonReleaseForLogout:(id)sender
{
    lylogin = [[LYLogin alloc]init];
    Boolean login_result = [lylogin logOut];
    if(login_result == YES){
        [btn_logout removeFromSuperview];
        [btn_fill removeFromSuperview];
        [self loadloginview];
    }
}

//返回按钮操作
-(void)buttonReleaseForCancel:(id)sender
{
    //解决显示网页后回跳时页面仍有显示的问题
    UIWebView* WebView  = [[ UIWebView   alloc]  initWithFrame: CGRectMake(0, 0,768, 1024)];
    [WebView loadHTMLString:@" " baseURL:nil];
    [self addSubview:WebView];
    //
    [titleLabel removeFromSuperview];
    [label1 removeFromSuperview];
    [label2 removeFromSuperview];
    [accountField removeFromSuperview];
    [passwdField removeFromSuperview];
    [label3 removeFromSuperview];
    [passwdField_again removeFromSuperview];
     
    [btn_cancel removeFromSuperview];
    [btn_register removeFromSuperview];
    
    [self loadloginview];
}

//注册完成按钮操作
-(void)buttonReleaseForRegisterSubmit:(id)sender
{
    if([accountField text] == nil || [accountField text].length == 0){
        alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                          message:@"请输入用户名"
                                         delegate:self
                                cancelButtonTitle:@"取消"
                                otherButtonTitles:nil
                 ];
        [alert show];
        [alert release];
        return;
    }
    if([passwdField text] == nil || [passwdField text].length == 0){
        alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                          message:@"请输入密码"
                                         delegate:self
                                cancelButtonTitle:@"取消"
                                otherButtonTitles:nil
                 ];
        [alert show];
        [alert release];
        return;
    }
    if([passwdField_again text] == nil || [passwdField_again text].length == 0){
        alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                          message:@"请输入确认密码"
                                         delegate:self
                                cancelButtonTitle:@"取消"
                                otherButtonTitles:nil
                 ];
        [alert show];
        [alert release];
        return;
    }
    if(![[passwdField text] isEqualToString:[passwdField_again text]]){
        alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                          message:@"两次输入的密码不相同，请重新设置密码"
                                         delegate:self
                                cancelButtonTitle:@"取消"
                                otherButtonTitles:nil
                 ];
        passwdField.text = nil;
        passwdField_again.text = nil;
        [alert show];
        [alert release];
        return;
    }
    //NSMutableDictionary *data = [NSMutableDictionary dictionary];
    //[data setValue:[accountField text] forKey:@"name"];
    //[data setValue:[passwdField text] forKey:@"password"];
    lylogin = [[LYLogin alloc]init] ;
    Boolean registerresult = [lylogin registerUser:[accountField text] password:[passwdField text]];
    if (registerresult == YES) {
        [lylogin logIn:[accountField text] password:[passwdField text]];
        [label1 removeFromSuperview];
        [label2 removeFromSuperview];
        [label3 removeFromSuperview];
        [accountField removeFromSuperview];
        [passwdField removeFromSuperview];
        [passwdField_again removeFromSuperview];
        [btn_cancel removeFromSuperview];
        [btn_register removeFromSuperview];
        [self showLoginPage];
    }else{
        //[self init];
    }
    [lylogin release];
}


//充值按钮操作
-(void)buttonReleaseForFill:(id)sender
{
     lyfill= [[LYFill alloc]init];
     lydb= [[LYDb alloc]init];
     userDefault = [NSUserDefaults standardUserDefaults];
     NSString* serverid = @"-1";
     NSString* orderid = @"82326389";
     NSString* uid = [userDefault objectForKey:@"uid"];
     NSString* money = @"1";
     NSString* productid= @"1";
     NSString* productname= @"gun";
    
    [lydb query_back:@"select * from note order by id desc" column:@"uid"];
    Boolean res = [lyfill billing:serverid orderid:orderid uid:uid money:money productid:productid productname:productname];
    //NSLog(@"%@",res);
    if(res == 1){
        NSLog(@"buttonReleaseForFill 返回计费结果：成功");
    }else{
        NSLog(@"buttonReleaseForFill 返回计费结果：失败");
    [lyfill loadFillPage:(UIView*)self
    serverid:(NSString*)serverid
    orderid:(NSString*) orderid
    uid:(NSString*)uid
    money:(NSString*)money
    productid:(NSString*)productid
    productname:(NSString*)productname];
        //[self loadFillPage];
    }
    [lyfill release];
}

//充值记录查询操作
-(void)buttonReleaseForFillRecord:(id)sender
{
    LeYou *leyou = [[LeYou alloc]init];
    userDefault = [NSUserDefaults standardUserDefaults];
    NSString* uid = [userDefault objectForKey:@"uid"];
    UIWebView* WebView  = [[ UIWebView   alloc]  initWithFrame: CGRectMake(0, 0,320, 1024)];
    NSString *url_base = LeYouApiUrlBase;
    NSString* url_api_for_findpaypass = [url_base stringByAppendingString:@"orderList.shtml"];
    NSURL *url = [NSURL URLWithString:url_api_for_findpaypass];
    NSString *mac = [leyou md5:[appid stringByAppendingFormat:@"%@%@",uid,PRIVATE_KEY]];
    /*
     NSLog(@"appid : %@",appid);
     NSLog(@"uid : %@",uid);
     NSLog(@"mac : %@",[appid stringByAppendingFormat:@"%@%@",uid,PRIVATE_KEY]);
     */
    //POST打开页面 关键次：UIWebview post值
    NSString *body = [NSString stringWithFormat: @"appid=%@&uid=%@&mac=%@",appid,uid,mac];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
    [request setHTTPMethod: @"POST"];
    [request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
    [WebView loadRequest: request];
    [self addSubview:WebView];

    
    
    
    /*
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
    [WebView loadRequest: request];
    [self addSubview:WebView];
     */
    //返回
    btn_cancel = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn_cancel setFrame:CGRectMake(180, 180.0f, 70, 30)];
    [btn_cancel setTitle:@"返回" forState:UIControlStateNormal];
    [btn_cancel addTarget:self action:@selector(buttonReleaseForReturnLoginedPage:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:btn_cancel];

}


-(void)buttonReleaseForReturnLoginedPage:(id)sender
{
    //解决显示网页后回跳时页面仍有显示的问题
    UIWebView* WebView  = [[ UIWebView   alloc]  initWithFrame: CGRectMake(0, 0,768, 1024)];
    [WebView loadHTMLString:@" " baseURL:nil];
    [self addSubview:WebView];
    //
    [self showLoginPage];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSLog(@"url :%@",[webView.request URL]);
    NSLog(@"url filename :%@",[[webView.request URL] lastPathComponent]);
    
    //NSLog(@"%@",[webView stringByEvaluatingJavaScriptFromString:@"document.orderid"]);
    if([[[webView.request URL] lastPathComponent] isEqualToString:@"success.shtml"])
    {
        //充值成功
        lydb = [[LYDb alloc]init];
        [lydb open];
        NSString* res = [lydb query_back:@"select * from orderinfo order by id desc" column:@"orderid"];
        NSLog(@"webViewDidFinishLoad orderid:%@",res);
        [lydb release];
        Boolean queryorderResult = [lyfill queryorder:res];
        if (queryorderResult == 1) {
            NSLog(@"webViewDidFinishLoad 返回计费结果：成功");
        } else {
            NSLog(@"返回计费结果：失败");
        }
    }else{
        //充值失败
    }
    //ttp://api.aigame365.com/shenzhoufu/order2.shtml succ
}
@end
